package lc;

import org.junit.Test;

public class Ex459 {

    class Solution {
        public boolean repeatedSubstringPattern(String s) {
            int idx = 1;
            for (char c: s.toCharArray()) {
                if (idx > s.length() / 2) break;
                if (check(s.substring(0, idx), s.substring(idx))) {
                    return true;
                }
                idx++;
            }
            return false;
        }
    
        public boolean check(String s, String str) {
            if (str.length() == 0)  return true;
            if (s.length() > str.length()) return false;
            String ss = str.substring(0, s.length());
            if (!s.equals(ss)) return false;
            return check(s, str.substring(s.length()));
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        System.out.println(s.repeatedSubstringPattern("aabaaba"));        
    }
    
}
